﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using ITProject.WebUI.Models.Project;
using System.ComponentModel.DataAnnotations;
using ITProject.Domain.Entities;
using ITProject.WebUI.Models.ProjectAdmin;

namespace ITProject.WebUI.Models.ProjectUser
{
    public class ProjectUserMyTaskDetailsViewModel
    {
        [Display(Name = "Nazwa")]
        public string Name { get; set; }
        [Display(Name = "Status")]
        public string Status { get; set; }
        [Display(Name = "Priorytet")]
        public string Priority { get; set; }
        [Display(Name = "Planowana data zakończenia")]
        public string PlannedEndDate { get; set; }
        [Display(Name = "Opis")]
        public string Description { get; set; }
        [Display(Name = "Data rozpoczęcia")]
        public string StartDate { get; set; }
        [Display(Name = "Funkcjonalność")]
        public string Feature { get; set; }

        public StatusChangeViewModel[] TaskStatusChanges { get; set; }

        // ukryte
        public int TaskId { get; set; }

        public static ProjectUserMyTaskDetailsViewModel Convert(Task task, StatusChange[] scTab, string[] userStatusChangeTab, string FeatureName = "")
        {
            ProjectUserMyTaskDetailsViewModel vm = new ProjectUserMyTaskDetailsViewModel();
            vm.Priority = PriorityViewModel.ConvertFromByte(task.Priority);
            vm.Status = StatusName.ConvertFromByte(task.Status);
            vm.Name = task.Name;
            vm.Description = task.Description;
            vm.PlannedEndDate = task.PlannedStopDate.ToLongDateString();
            vm.StartDate = task.StartDate.ToLongDateString();
            if (FeatureName == "")
                vm.Feature = ProjectAdminAddNewTaskViewModel.NoFeature;
            else
                vm.Feature=FeatureName;
            vm.TaskStatusChanges = new StatusChangeViewModel[scTab.Length];
            for (int i = 0; i < scTab.Length; i++)
                vm.TaskStatusChanges[i] = new StatusChangeViewModel
                {
                    Comment = scTab[i].Comment,
                    DateOfChange = scTab[i].DateOfChange,
                    User = userStatusChangeTab[i],
                    OldStatus = StatusName.ConvertFromByteNullable(scTab[i].OldStatus),
                    NewStatus = StatusName.ConvertFromByte(scTab[i].NewStatus)
                };
            return vm;
        }
    }
}